package com.example.administrator.yuejian2.activity;

import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.adapter.ShareFragmentPagerAdapter;
import com.example.administrator.yuejian2.adapter.mFragmentPagerAdapter;
import com.example.administrator.yuejian2.bean.SharePictureBean;
import com.example.administrator.yuejian2.model.SharePicModel;
import com.squareup.picasso.Picasso;

import static com.example.administrator.yuejian2.other.Url.IMAGEURL;

public class Share_DetailActivity extends BaseActivity {

    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ShareFragmentPagerAdapter mFragPAdapter;
    private Toolbar toolbar;
    private ImageView share_picture_backpic;
    private String share_id,picTitle;
    private RetrofitListener<SharePictureBean> listener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share__detail);
        listener=new RetrofitListener<SharePictureBean>() {
            @Override
            public void onSuccess(SharePictureBean sharePictureBean, int flag) {
                Picasso.with(Share_DetailActivity.this).load(IMAGEURL+sharePictureBean.getPicture_pic()).into(share_picture_backpic);
                picTitle=sharePictureBean.getPicture_title();
                toolbar.setTitle(picTitle);
                setSupportActionBar(toolbar);
            }

            @Override
            public void onFail() {

            }
        };
        initView();
        Intent intent = getIntent();
        share_id = intent.getStringExtra("s_id");

        SharePicModel sharePicModel=new SharePicModel();
        sharePicModel.sharepicDetail(share_id,listener);
    }
    private void initView()
    {
        tabLayout = findViewById(R.id.share_picture_tablayout);
        viewPager = findViewById(R.id.share_picture_viewPager);
        toolbar =  findViewById(R.id.share_picture_toolbar);
        share_picture_backpic=findViewById(R.id.share_picture_backpic);
        mFragPAdapter=new ShareFragmentPagerAdapter(getSupportFragmentManager());
        viewPager.setAdapter(mFragPAdapter);
        tabLayout.setupWithViewPager(viewPager);
    }
}
